package com.session1;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class ValidForm extends JFrame implements ActionListener {
	private JTextField txt;
	private JButton btnCheck;
	public ValidForm(){
		
	}
	public void createForm(){
//		Khoi Tao Cac Thanh Phan Control
		
		this.txt = new JTextField(20);
		this.btnCheck = new JButton("Check");
		
		this.setLayout(new FlowLayout());
		this.getContentPane().add(this.txt);
		this.getContentPane().add(this.btnCheck);
//		Dang Ki Su Kien
		this.btnCheck.addActionListener(this);
	}
	public void showForm(){
		this.setTitle("Vaild Demo");
		this.setSize(400,300);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		ValidForm d = new ValidForm();
		d.createForm();
		d.showForm();
	}
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == this.btnCheck){
//			Sinh Ra Thanh Phan Relugx xet chuoi nhap vao phan dung JTextFile
			Pattern mau = Pattern.compile("\\d\\d+",Pattern.CASE_INSENSITIVE);
			Matcher matcher = mau.matcher(this.txt.getText());
			if(matcher.matches()){
				JOptionPane.showMessageDialog(this, "Ok Thanks You");
			}else{
				JOptionPane.showMessageDialog(this, "Fail,Try Again");
			}
		}
	}
	
}
